package com.sn.author.utils.export;

import com.sn.author.common.exception.BadRequestException;
import com.sn.author.domain.entity.ImportAccount;
import com.sn.author.utils.BeanUtils;
import com.sn.author.utils.Export;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.List;

public class AccountExport extends Export {

    public AccountExport(List<String> titles, String fileName) {
        super(titles, fileName);
    }

    @Override
    public Export writeData(List list) {
        if(list.isEmpty()){
            throw new BadRequestException("无数据可下载");
        }
        List<ImportAccount> importAccounts = BeanUtils.coventObject(list,ImportAccount.class);
        Sheet sheet = super.wb.getSheetAt(0);
        int cindex = 1;
        for (ImportAccount importAccount : importAccounts) {
            Row row = sheet.createRow(cindex);//从第二行开始保存数据
            row.createCell(0).setCellValue(importAccount.getId());
            row.createCell(1).setCellValue(importAccount.getPhone());
            row.createCell(2).setCellValue(importAccount.getLikeCnt());
            row.createCell(3).setCellValue(importAccount.getCommentCnt());
            row.createCell(4).setCellValue(importAccount.getAttentionCnt());
            row.createCell(5).setCellValue(importAccount.getProxyIp());
            row.createCell(6).setCellValue(importAccount.getLastLoginTime());
            cindex ++;
        }
        return this;
    }
}
